package com.pawn.exceptiondemo.utils;

import com.pawn.exceptiondemo.exception.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @program: springboot-1-cache
 * @description:
 * @author: Dawson.Zhang
 * @create: 2020-08-28
 **/
@RestControllerAdvice
public class MyControllerAdvice {
    public static final Logger LOGGER = LoggerFactory.getLogger(MyControllerAdvice.class);
    @ExceptionHandler(MyException.class)
    //表示值处理MyException 这个异常
    public ResUtil exception(MyException myException){
        LOGGER.error("MyException异常");
        return ResUtil.FAILED(ResCode.FAILED.getCode(),myException.getMessage());
    }

    @ExceptionHandler(Exception.class)
    //表示值处理MyException 这个异常
    public ResUtil exception(Exception e){
        LOGGER.error("全局统一异常");
        return ResUtil.FAILED(ResCode.FAILED.getCode(),e.getMessage());
    }
}
